<html>
<head>
<title>
</title>
</head>
<body>
<script language='JavaScript' type="text/javascript" src="./callAsAsynchronousFunction.js"></script>
<script language='JavaScript' type="text/javascript" src="./SynchronizationQueueManger.js"></script>
<script language='JavaScript' type="text/javascript" >
//debug日志输出
function log(str){
	otxt=document.getElementById("txt1");
	otxt.value =str+'\n'+otxt.value;
} 
</script>
<form id=frm1 name=frm1>
<input type=button onClick="javascript:btn_click();" value=test3 /><br/>
实例：使用2个队列——默认的和命名为mytest的<br/>日志:<br/>
<textarea id=txt1 name=txt1 cols=60 rows=20>---</textarea><br/>
</form>
<script language='JavaScript' type="text/javascript" >
//模拟异步：输入函数
function AsynchronousCall(oFunc,aVars){
	var vNum = Math.round(Math.random()*10);
	var sfuncName=oFunc.name;
	log("Func:"+ oFunc.name +" will called after "+ vNum +" sec.");
	callAsAsynchronousFunction(oFunc,aVars,vNum*1000);
}
//测试用的函数
function test1(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler(),[1])
}
function test2(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler(),[2])
}
function test3(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler(),[3])
	
}
function test1_rtn(){
	log("Func:"+arguments.callee.name+" returned." +arguments[0]);
}
function test2_rtn(){
	log("Func:"+arguments.callee.name+" returned." +arguments[0]);
}
function test3_rtn(){
	log("Func:"+arguments.callee.name+" returned." +arguments[0]);
}


function test1b(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler("mytest"),[100])
}
function test2b(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler("mytest"),[200])
}
function test3b(){
	log("Func:"+arguments.callee.name+" be called." +arguments[0]);
	AsynchronousCall(SynchronizationQueueManger.onRuturnHandler("mytest"),[300])
	
}
//主测试按钮1事件
function btn_click(){
	/**/
	var q=SynchronizationQueueManger.GetTheSynchronizationQueue();
	q.add( test1 , ['10','11'] , test1_rtn);
	q.add( test2 , ['20','21'] , test2_rtn);
	q.add( test3 , ['30','31'] , test3_rtn);
	var q2=SynchronizationQueueManger.GetTheSynchronizationQueue("mytest");
	q2.add( test1b , ['10','11'] , test1_rtn);
	q2.add( test2b , ['20','21'] , test2_rtn);
	q2.add( test3b , ['30','31'] , test3_rtn);
	q2.start();
	q.start();
	/**/
}
</script>
</body>
</html>

